package demo1enum;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 牛孟俊
 * Date: 2023-11-21
 * Time: 16:26
 */
public class Test {

    public static void reflectPrivateConstructor() {
        try {
            Class<?> c1 = Class.forName("demo1enum.TestEnum");//获取到了class对象

            //获取私有的构造方法
            Constructor<?> constructor = c1.getDeclaredConstructor(double.class,String.class);

            constructor.setAccessible(true);

            TestEnum testEnum = (TestEnum) constructor.newInstance(9.9,"天青色");

            System.out.println(testEnum);

        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
       // System.out.println(Constant.BLACK);

        reflectPrivateConstructor();
    }
}
